package com.frcdi.qms.web.controller.equipment;

import com.frcdi.qms.common.core.controller.BaseController;
import com.frcdi.qms.common.core.domain.AjaxResult;
import com.frcdi.qms.common.core.page.TableDataInfo;
import com.frcdi.qms.common.utils.poi.ExcelUtil;
import com.frcdi.qms.equipment.domain.EquipmentCycle;
import com.frcdi.qms.equipment.service.IEquipmentCycleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 设备生命周期Controller
 *
 * @author cell
 * @date 2023-12-12
 */
@Api(tags = "设备生命周期")
@RestController
@RequestMapping("/equipment/cycle")
public class EquipmentCycleController extends BaseController
{
    @Autowired
    private IEquipmentCycleService equipmentCycleService;

    /**
     * 查询设备生命周期列表
     */
    @ApiOperation("查询设备生命周期列表")
    @PreAuthorize("@ss.hasPermi('equipment:equipmentBase:edit')")
    @GetMapping("/list")
    public TableDataInfo list(EquipmentCycle equipmentCycle)
    {
        startPage();
        List<EquipmentCycle> list = equipmentCycleService.selectEquipmentCycleList(equipmentCycle);
        return getDataTable(list);
    }

    /**
     * 导出设备生命周期列表
     */
    @ApiOperation("导出设备生命周期列表")
    @PreAuthorize("@ss.hasPermi('equipment:equipmentBase:edit')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, EquipmentCycle equipmentCycle)
    {
        List<EquipmentCycle> list = equipmentCycleService.selectEquipmentCycleList(equipmentCycle);
        ExcelUtil<EquipmentCycle> util = new ExcelUtil<EquipmentCycle>(EquipmentCycle.class);
        util.exportExcel(response, list, "设备生命周期数据");
    }

    /**
     * 获取设备生命周期详细信息
     */
    @ApiOperation("获取设备生命周期详细信息")
    @PreAuthorize("@ss.hasPermi('equipment:equipmentBase:edit')")
    @GetMapping(value = "/{cycleStatus}")
    public AjaxResult getInfo(@PathVariable("cycleStatus") String cycleStatus)
    {
        return success(equipmentCycleService.selectEquipmentCycleByCycleStatus(cycleStatus));
    }
}
